﻿using mscook.core.domain;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate.Linq;

namespace mscook.core.repositories
{
    public class BonusOrderRepository:Repository<BonusOrder>, mscook.core.repositories.IBonusOrderRepository
    {
        public IList<BonusOrder> GetByLoginUser(LoginUser loginUser,int start,int limit,out long total)
        {
            var query = (from x in this.Session.Query<BonusOrder>() select x)
             .Where(o => o.IsDelete == false
                 && o.LoginUser==loginUser).OrderByDescending(o => o.EntityIndex).OrderByDescending(o => o.CreateTime);
            total = query.Count();
            return query.Skip(start).Take(limit).ToList();
        }

        public IList<BonusOrder> GetByLoginUser(LoginUser loginUser)
        {
            var query = (from x in this.Session.Query<BonusOrder>() select x)
             .Where(o => o.IsDelete == false
                 && o.LoginUser == loginUser).OrderByDescending(o => o.EntityIndex).OrderByDescending(o => o.CreateTime);
            return query.ToList();
        }

        public BonusOrder GetByOrderNumber(string orderNumber)
        {
            var query = (from x in this.Session.Query<BonusOrder>() select x)
             .Where(o => o.IsDelete == false
                 && o.OrederNumber == orderNumber).OrderByDescending(o => o.EntityIndex).OrderByDescending(o => o.CreateTime);
            return query.SingleOrDefault();
        }

    }
}
